package com.qyl.deguru.controller.customer;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qyl.deguru.common.PageModel;
import com.qyl.deguru.common.QueryVo;
import com.qyl.deguru.dto.Shop;
import com.qyl.deguru.dto.ShopType;
import com.qyl.deguru.service.ShopService;
import com.qyl.deguru.service.ShopTypeService;
import com.qyl.deguru.service.impl.ShopServiceImple;
import com.qyl.deguru.service.impl.ShopTypeServcieImple;
/**
 * 商品列表
 * */
@Controller
@RequestMapping("/customer/shops")
public class ShopListController {
	ShopTypeService shopTypeService=new ShopTypeServcieImple();
	ShopService shopService=new ShopServiceImple();
	//根据商品类型跳转到商品列表信息
	@RequestMapping("/toShopList")
	public String toShopList(String pageIndex,String pageSize,String tcode,ModelMap modelMap){
		//引入分页
		PageModel pageModel=new PageModel();
		//判断当前页是否为空
		if("".equals(pageIndex) || pageIndex==null) {
			pageModel.setPageIndex(0);
		}else {
			pageModel.setPageIndex(Integer.parseInt(pageIndex));
		}
		//判断每页记录是否大于0
		if(pageSize!=null &&pageSize!="") {
			pageModel.setPageSize(Integer.parseInt(pageSize));
		}else{
			pageModel.setPageSize(5);
		}
		//获取总记录数
		int count=shopTypeService.getcount();
		pageModel.setRecordCount(count);
		//商品类型[8位]
		List<ShopType> shopType=shopTypeService.getShopTypeLimit8(tcode); 
		modelMap.addAttribute("shopType", shopType);
		//通过4位的code获取多个8位的code
		String[] codes=shopTypeService.getShopeCode(tcode);
		System.out.println(codes+"shuzu");
		//根据[4位]商品类型获取[8位]商品信息
		QueryVo queryVo = new QueryVo();
		queryVo.setArray(codes);
		queryVo.setPageModel(pageModel);
		List<Shop> shops=shopService.getShopByCode(queryVo);
		modelMap.addAttribute("shops", shops);
		modelMap.addAttribute("pageModel", pageModel);
		return "shop_list";
	}
}
